<template>
	<view style="width: 100%;">
	<view v-for="(item,index) in richContent" :key="index" style="width: 100%;">
		<view @longpress="copyContent(item.content)" v-if="item.type=='text'" class="padding-top-xs padding-bottom-xs" style="width: 100%;">
			<view v-if="item.content&&item.content.length < 150">
				<rich-text :selectable="true" class="text-lg text-black content-space" :nodes="item.content.replace(reg, emotion)"></rich-text>
			</view>
			<view @tap.stop="expandContent" v-else-if="isExpand" class="flex justify-start align-start" style="flex-direction: column;">
				<rich-text :selectable="true" class="text-lg text-black content-space" :nodes="item.content.replace(reg, emotion)"></rich-text>
				<text v-if="hideExpandBtn==false" class="action text-blue text-sm">收起</text>
			</view>
			<view @tap.stop="expandContent" v-else class="flex justify-start align-start" style="flex-direction: column;">
				<rich-text  :selectable="true" class="text-lg text-black content-space" :nodes="summaryText.replace(reg, emotion)"></rich-text>
				<text v-if="hideExpandBtn==false" class="action text-blue text-sm">展开</text>
			</view>			
		</view>
		<view v-if="item.type=='audio'" class="padding-top-xs padding-bottom-xs" style="width: 80%;">
			<audio-player :src="item.url" :initDuration="item.duration" style="width: 80%;"></audio-player>
		</view>
		<view v-if="item.type=='grid_image'" style="width: 100%;">
			<image-box :num="item.url_list.length" :imgList="item.url_list" style="width: 100%;"></image-box>
		</view>
		<view v-if="item.type=='video'" class="padding-top-xs padding-bottom-xs" style="width: 100%;">
			<view style="position: relative;width: 100%;">
				<video :id="'video-player'" @tap="clickVideoPlay(item.url)" :muted="true" :autoplay="false" :enable-play-gesture="false" :controls="false" :show-center-play-btn="false" class="video-style" :src="item.url" objectFit="cover">
					<view class="video-mask flex justify-center align-center">
						<image src="../static/images/setting/video-play.png" style="width: 80%;height: 80%;"></image>
					</view>
				</video>
			</view>
		</view>
	</view>
	</view>
</template>

<script>
	import AudioPlayer from '@/components/audio-player.vue'
	import ImageBox from '@/components/imagebox.vue'
	export default {
		name:"RichActiveDisplay",
		components: {
			AudioPlayer,
			ImageBox
		},
		data() {
			return {
				hideExpandBtn:false,
				reg: /\#[\S]{1,3}\;/gi
			}
		},
		computed: {
			summaryText() {
				let text = ''
				this.richContent.forEach(item=>{
					if(item.type == 'text') {
						if(item.content.length > 150)  {
							text = item.content.slice(0,149)+'...'
						}else{
							text = item.content
						}
					}
				})
				return text
			}
		},
		props: {
			richContent: {
				type: Array,
				default: []
			},
			isExpand:{
				type:Boolean,
				default:false
			}
		},
		mounted() {
			let videoContext = uni.createVideoContext('video-player')
			videoContext.pause()
		},
		methods: {
			copyContent(content) {
				uni.setClipboardData({
					data: content,
					success: function() {
						uni.showToast({
							icon: 'none',
							title: '内容已复制!'
						});
					}
				});
			},
			textLongPress() 
			{
				this.$emit('textPress')
			},
			expandContent() 
			{
				this.$emit('expand')
			},
			clickVideoPlay(url) 
			{
				this.$emit('videoPlay',url)
			},
			emotion(res) {
				//console.log('mess', res)
				let word = res.replace(/\#|\;/gi, '')
				//console.log(word)
				const list = ['微笑', '撇嘴', '色', '发呆', '得意', '流泪', '害羞', '闭嘴', '睡', '大哭', '尴尬', '发怒', '调皮', '呲牙', '惊讶', '难过', '酷',
					'冷汗', '抓狂', '吐', '偷笑', '可爱', '白眼', '傲慢', '饥饿', '困', '惊恐', '流汗', '憨笑', '大兵', '奋斗', '咒骂', '疑问', '嘘', '晕', '折磨', '衰',
					'骷髅', '敲打', '再见', '擦汗', '抠鼻', '鼓掌', '糗大了', '坏笑', '左哼哼', '右哼哼', '哈欠', '鄙视', '委屈', '快哭了', '阴险', '亲亲', '吓', '可怜',
					'菜刀', '西瓜', '啤酒', '篮球', '乒乓', '咖啡', '饭', '猪头', '玫瑰', '凋谢', '示爱', '爱心', '心碎', '蛋糕', '闪电', '炸弹', '刀', '足球', '瓢虫',
					'便便', '月亮', '太阳', '礼物', '拥抱', '强', '弱', '握手', '胜利', '抱拳', '勾引', '拳头', '差劲', '爱你', 'NO', 'OK', '爱情', '飞吻', '跳跳',
					'发抖', '怄火', '转圈', '磕头', '回头', '跳绳', '挥手', '激动', '街舞', '献吻', '左太极', '右太极'
				]
				let index = list.indexOf(word)
				return `<img src="https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/${index}.gif" style="vertical-align:middle;" width="22" height="22">`
			}
		},
	}
</script>

<style lang="scss" scoped>
	.video-style {
		width: 100%;
		height: #{width};
	}
.video-mask {
	position: absolute;
	z-index: 99;
	top:35%;
	left:39%;
	width:160upx;
	height: 160upx;
}
.content-space {
	letter-spacing: 1.5upx;
}
</style>